package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.storeOrderCartReturn.IDeleteStoreOrderCartReturnBMO;
import com.java110.mall.cart.bmo.storeOrderCartReturn.IGetStoreOrderCartReturnBMO;
import com.java110.mall.cart.bmo.storeOrderCartReturn.ISaveStoreOrderCartReturnBMO;
import com.java110.mall.cart.bmo.storeOrderCartReturn.IUpdateStoreOrderCartReturnBMO;
import com.java110.mall.cart.bmo.storeOrderCartReturnEvent.IGetStoreOrderCartReturnEventBMO;
import com.java110.dto.storeOrder.StoreOrderCartReturnEventDto;
import com.java110.po.storeOrder.StoreOrderCartReturnPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping(value = "/storeOrderCartReturn")
public class StoreOrderCartReturnApi {

    @Autowired
    private ISaveStoreOrderCartReturnBMO saveStoreOrderCartReturnBMOImpl;
    @Autowired
    private IUpdateStoreOrderCartReturnBMO updateStoreOrderCartReturnBMOImpl;
    @Autowired
    private IDeleteStoreOrderCartReturnBMO deleteStoreOrderCartReturnBMOImpl;

    @Autowired
    private IGetStoreOrderCartReturnBMO getStoreOrderCartReturnBMOImpl;

    @Autowired
    private IGetStoreOrderCartReturnEventBMO getStoreOrderCartReturnEventBMOImpl;

    /**
     * 批量发起退货申请（商家申请销售退货）
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartReturn/applyReturnStoreOrder
     * @path /app/storeOrderCartReturn/applyReturnStoreOrder
     */
    @RequestMapping(value = "/applyReturnStoreOrder", method = RequestMethod.POST)
    public ResponseEntity<String> applyReturnStoreOrder(
            @RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含商铺");
        Assert.hasKeyAndValue(reqJson, "orderId", "请求报文中未包含订单");
        Assert.hasKeyAndValue(reqJson, "remark", "请求报文中未包含备注");

        return saveStoreOrderCartReturnBMOImpl.applyReturnStoreOrder(reqJson);
    }



    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /storeOrderCartReturn/deleteStoreOrderCartReturn
     * @path /app/storeOrderCartReturn/deleteStoreOrderCartReturn
     */
    @RequestMapping(value = "/deleteStoreOrderCartReturn", method = RequestMethod.POST)
    public ResponseEntity<String> deleteStoreOrderCartReturn(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "returnId", "returnId不能为空");


        StoreOrderCartReturnPo storeOrderCartReturnPo = BeanConvertUtil.covertBean(reqJson, StoreOrderCartReturnPo.class);
        return deleteStoreOrderCartReturnBMOImpl.delete(storeOrderCartReturnPo);
    }


    /**
     * 微信删除消息模板
     *
     * @param storeId 商户ID
     * @return
     * @serviceCode /storeOrderCartReturnEvent/queryStoreOrderCartReturnEvent
     * @path /app/storeOrderCartReturnEvent/queryStoreOrderCartReturnEvent
     */
    @RequestMapping(value = "/queryStoreOrderCartReturnEvent", method = RequestMethod.GET)
    public ResponseEntity<String> queryStoreOrderCartReturnEvent(@RequestParam(value = "returnId") String returnId,
                                                                 @RequestParam(value = "storeId") String storeId,
                                                                 @RequestParam(value = "page") int page,
                                                                 @RequestParam(value = "row") int row) {
        StoreOrderCartReturnEventDto storeOrderCartReturnEventDto = new StoreOrderCartReturnEventDto();
        storeOrderCartReturnEventDto.setPage(page);
        storeOrderCartReturnEventDto.setRow(row);
        storeOrderCartReturnEventDto.setReturnId(returnId);
        return getStoreOrderCartReturnEventBMOImpl.get(storeOrderCartReturnEventDto);
    }
}
